package thread;
//
//public class ThreadDemo25 {
//    public static void main(String[] args) {
//        Object locker = new Object();
//        Thread t1 = new Thread(()->{
//            synchronized (locker) {
//                System.out.println("t1 wait 之前");
//                try {
//                    locker.wait();
//                }catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                System.out.println("t1 wait 之后");
//            }
//        });
//
//        Thread t2 = new Thread(()->{
//            try {
//                Thread.sleep(5000);
//
//                synchronized (locker) {
//                    System.out.println("t2 notify 之前");
//                    locker.notify();
//                    System.out.println("t2 notify 之后");
//                }
//            }catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        });
//
//        t1.start();
//        t2.start();
//    }
//}

public class ThreadDemo25{
    public static void main(String[] args) {
        Object locker = new Object();
        Thread t1 = new Thread(()->{
            synchronized (locker) {
                System.out.println("t1 wait 之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("t1 wait 之后");
            }
        });

        Thread t2 = new Thread(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized (locker) {
                System.out.println("t2 notify 之前");
                locker.notifyAll();
                System.out.println("t2 notify 之后");
            }
        });

        t1.start();
        t2.start();
    }
}